package com.xcc.java_base;

public class Demo02_CaseSwitch {

    public static void main(String[] args) {
        test01();
        test02();
    }

    /**
     * 输出结果为10
     *  首先switch匹配到2 result = 4
     *  然后没有break继续匹配3 result = 4 + 6 = 10
     */
    private static void test02() {
        int i = 2;
        int result = 0;
        switch (i) {
            case 1:
                result = result + i;
            case 2:
                result = result + i * 2;
            case 3:
                result = result + i * 3;
        }
        System.out.println(result);
    }

    /**
     * switch匹配从上到下
     */
    private static void test01() {
        int i = 2;
        switch (i) {
            default:
                System.out.println("default");
            case 0:
                System.out.println(0);
                break;
            case 1:
                System.out.println(1);
                break;
            case 2:
                System.out.println(2);
        }
    }

}
